package com.taotao.thread.Test1;

/**
 * @author wangjin
 * @title: Test5
 * @projectName thread
 * @description: TODO
 * @date 2022/5/3 0003 15:31
 */
public class Account {
    String name;
    double balance;

    public synchronized void set(String name, double balance) {
        this.name = name;
        try {
            Thread.sleep(100);
        } catch (Exception e) {
            e.getMessage();
        }
        this.balance = balance;
    }

    public double getBalance(String name) {
        return this.balance;
    }

    public static void main(String[] args) {
        Account account = new Account();
        new Thread(()->{
            account.set("zhangshan",100.00);
        }).start();
        try {
            Thread.sleep(100);
        }catch (Exception e){
            e.getMessage();
        }

        System.out.println(account.getBalance("zhangshan"));
        try {
            Thread.sleep(100);
        }catch (Exception e){
            e.getMessage();
        }
        System.out.println(account.getBalance("zhangshan"));
    }
}
